package com.zxs.infra.basic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zxs.infra.basic.entity.SubjectMultiple;
import com.zxs.infra.basic.entity.SubjectRadio;
import com.zxs.infra.basic.mapper.SubjectMultipleMapper;
import com.zxs.infra.basic.service.SubjectMultipleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 多选题选项表(SubjectMultiple)表服务实现类
 *
 * @author makejava
 * @since 2025-11-12 21:05:48
 */
@Service
public class SubjectMultipleServiceImpl implements SubjectMultipleService {
    @Autowired
    private SubjectMultipleMapper subjectMultipleMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SubjectMultiple queryById(Integer id) {
        return this.subjectMultipleMapper.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param subjectMultiple 实例对象
     * @return 实例对象
     */
    @Override
    public SubjectMultiple insert(SubjectMultiple subjectMultiple) {
        this.subjectMultipleMapper.insert(subjectMultiple);
        return subjectMultiple;
    }

    /**
     * 修改数据
     *
     * @param subjectMultiple 实例对象
     * @return 实例对象
     */
    @Override
    public SubjectMultiple update(SubjectMultiple subjectMultiple) {
        this.subjectMultipleMapper.update(subjectMultiple);
        return this.queryById(subjectMultiple.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.subjectMultipleMapper.deleteById(id) > 0;
    }

    @Override
    public Integer batchInsert(List<SubjectMultiple> subjectMultiples) {
        return subjectMultipleMapper.insertBatch(subjectMultiples);
    }

    @Override
    public List<SubjectMultiple> queryBySubjectId(int subjectId) {
        LambdaQueryWrapper<SubjectMultiple> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SubjectMultiple::getSubjectId, subjectId)
                .eq(SubjectMultiple::getIsCorrect, 1);
        List<SubjectMultiple> subjectMultiple = subjectMultipleMapper.selectList(queryWrapper);
        return subjectMultiple;
    }
}
